// Marker Script and Setiings for civs, truck, cops
// markers.sqf

_civnumber = _this select 0;
if (_civnumber == 0) exitWith {};
// For Convoy
if (_civnumber == 1) then {
	_markerobj = createMarker["konvoy_marker",[0,0]];
	_markername= "konvoy_marker";
	_markerobj setMarkerShape "ICON";
	"konvoy_marker" setMarkerType "Marker";
	"konvoy_marker" setMarkerColor "ColorYellow";
	"konvoy_marker" setMarkerText localize "STRS_Konvoymarker";
	while {true} do {
		_markername SetMarkerPos [(getMarkerPos "marker_dead" select 0)-1000,(getMarkerPos "marker_dead" select 1)-1000];
		waitUntil {(konvoy_marker_active == 1)};
		while {konvoy_marker_active == 1} do {
			_markername SetMarkerPos getpos konvoytruck;
			sleep 5;
		};
	};
};

if (_civnumber == 3) then
{
	private ["_civStringArray", "_civArray"];
	if (isCop) then
	{
		_civStringArray = civstringarray - undercoverstringarray;
		_civArray = civarray - undercoverarray;
	}
	else
	{
		_civStringArray = civstringarray;
		_civArray = civarray;
	};
	
	_markerArray = [];
	{
		_markername = format ["%1_marker", _x];
		_civmarker  = createmarkerLocal [_markername, [-1000, -1000] ];
		_markername setMarkerShapeLocal "ICON";
		_markername setMarkerTypeLocal  "Destroy";
		_markername setMarkerColorLocal "ColorYellow";
		_markername setMarkerSizeLocal  [0.5, 0.5];
		_markerArray = _markerArray + [_markername];
	} forEach _civStringArray;

	while {true} do
	{
		
		_i = 0;
		{
			_civstring = format ["%1", _x];
			_markerName = _markerArray select _i;
			_civ = _x;
			_show = false;
			
			if (_civstring call ISSE_UnitExists) then
			{
				{
					if ( (_civ distance (_x select 0) < (_x select 1)) && (player != vehicle player) ) exitWith
					{
						_show = true;
					};
				} forEach CityLocationArray;
			};
			
			if (_show) then
			{
				if ((call compile format ["%1_wanted;", _civstring]) == 1) then
				{
					_markername setMarkerColorLocal "ColorRed";
				}
				else
				{
					_markername setMarkerColorLocal "ColorYellow";
				};
				
				_markerName setMarkerPosLocal [(getPos _x select 0) + 25 - (random 50), (getPos _x select 1) + 25 - (random 50)];
			}
			else
			{
				_markerName setMarkerPosLocal [0,0];
			};
			_i = _i + 1;
		} forEach _civArray;
		
		sleep marker_innerhalb;
	};
};

// For cops
if (_civnumber == 2) then
{
	if (not(iscop)) exitWith {}; //These markers shouldn't show for civs

	
	_copnumber = 1;
	_copmarkerarray = [];
	_copmarkernamearray = [];
	while {_copnumber <= copscount} do
	{
		_copmarker  = createMarkerLocal[format["cop%1_marker", _copnumber], [-100, -100]];
		_copmarkerarray = _copmarkerarray + [_copmarker];
		_markername  = format["cop%1_marker", _copnumber];
		_copmarkernamearray   = _copmarkernamearray + [_markername];
		_markername setMarkerShapeLocal "ICON";
		_markername setMarkerTypeLocal  "Destroy";
		_markername setMarkerColorLocal "ColorGreen";
		_markername setMarkerSizeLocal  [0.5, 0.5];
		format["cop%1_marker", _copnumber] setMarkerTextLocal format["Cop%1" , _copnumber];
		_copnumber = _copnumber + 1;
	};
	{_x SetMarkerPosLocal [(getMarkerPos "marker_dead" select 0)-1000,(getMarkerPos "marker_dead" select 1)-1000]} forEach _copmarkernamearray;
	
	_ucaMarkerarray = [];
	_ucaMarkernamearray =[];
	_ucaNumber = 1;
	while {_ucaNumber <= (count undercoverarray)} do
	{
		_ucaMarker  = createMarkerLocal[format["uca%1_marker", _ucaNumber], [-100, -100]];
		_ucaMarkerarray = _copmarkerarray + [_ucaMarker];
		_markername  = format["uca%1_marker", _ucaNumber];
		_ucaMarkernamearray   = _ucaMarkernamearray + [_markername];
		_ucaMarker setMarkerShapeLocal "ICON";
		_markername setMarkerTypeLocal  "Destroy";
		_markername setMarkerColorLocal "ColorYellow";
		_markername setMarkerSizeLocal  [0.5, 0.5];
		format["uca%1_marker", _ucaNumber] setMarkerTextLocal format["UCA%1" , _ucaNumber];
		_ucaNumber = _ucaNumber + 1;
	};
	{_x SetMarkerPosLocal [(getMarkerPos "marker_dead" select 0)-1000,(getMarkerPos "marker_dead" select 1)-1000]} forEach _ucaMarkernamearray;
	
	
	_copAndUca = coparray + undercoverarray;
	_copUcaMarkerNameArray = _copmarkernamearray + _ucaMarkernamearray;
	while {true} do
	{
		_counter = 0;
		while {_counter < count _copAndUca} do
		{
			_cop = _copAndUca select _counter;
			private "_isUCA";
			if (_cop in undercoverarray) then
			{
				_isUCA = true;
			}
			else
			{
				_isUCA = false;
			};

			if (!( (format["%1", (_cop)]) call ISSE_UnitExists)) then
			{ //don't show if: Unit doesn't exist OR cop markers are off OR player is on foot
				(_copUcaMarkerNameArray select _counter) SetMarkerPosLocal (getmarkerpos "marker_dead");
			}
			else
			{
				if (alive _cop) then
				{
					(_copUcaMarkerNameArray select _counter) SetMarkerPosLocal [position _cop select 0, position _cop select 1];
					
					//_isUCA = false;
					if ((call compile format ["%1_needSupport", _cop])) then
					{
						if (_isUCA) then
						{
							(_copUcaMarkerNameArray select _counter) setMarkerColorLocal "ColorBlack";
						}
						else
						{
							(_copUcaMarkerNameArray select _counter) setMarkerColorLocal "ColorBlue";
						};
					}
					else
					{
						if (_isUCA) then
						{
							(_copUcaMarkerNameArray select _counter) setMarkerColorLocal "ColorWhite";
						}
						else
						{
							(_copUcaMarkerNameArray select _counter) setMarkerColorLocal "ColorGreen";
						};
					};
					
					if (_cop == vehicle _cop) then //cop is on foot
					{
						(_copUcaMarkerNameArray select _counter) setMarkerTypeLocal "Vehicle";
						(_copUcaMarkerNameArray select _counter) setMarkerSizeLocal  [0.8, 0.8];
					}
					else //cop is in a vehicle
					{
						(_copUcaMarkerNameArray select _counter) setMarkerTypeLocal "Destroy";
						(_copUcaMarkerNameArray select _counter) setMarkerSizeLocal  [0.5, 0.5];
					};
				};
			};
			_counter = _counter + 1;
		};
		sleep 5;
	};
};